package com.tobby.camel.camelinaction.chapter3.order;

import java.util.List;

import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.spring.CamelSpringTestSupport;
import org.junit.Test;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class PurchaseOrderCsvSpringTest extends CamelSpringTestSupport {

	@Override
	protected AbstractApplicationContext createApplicationContext() {
		return new ClassPathXmlApplicationContext(
				"com/tobby/camel/camelinaction/chapter3/order/order-csv.xml");
	}

	@Test
	public void testCsv() throws InterruptedException {
		MockEndpoint endpoint = getMockEndpoint("mock:queue.csv");
		endpoint.expectedMessageCount(2);
		assertMockEndpointsSatisfied();

		List line1 = endpoint.getReceivedExchanges().get(0).getIn().getBody(List.class);
		System.out.println("------------aaaaaaaaaaaaaaa" + line1);
		assertEquals("Camel in Action", line1.get(0));
		assertEquals("4995", line1.get(1));
		assertEquals("1", line1.get(2));

		List line2 = endpoint.getReceivedExchanges().get(1).getIn().getBody(List.class);
		System.out.println("----------------" + line2);
		assertEquals("Camel in Action", line1.get(0));
		assertEquals("4995", line1.get(1));
		assertEquals("1", line1.get(2));
	}

}
